package hn.cch.performance.controller;

import hn.cch.performance.excutor.MyThreadPoolExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


@RequestMapping(value = "/my")
@RestController
public class MyRestController {

    private static final Logger logger = LoggerFactory.getLogger(MyRestController.class);


    @GetMapping(value = "/get")
    public String get() {
        logger.info("GET");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 4, 1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4));
        threadPoolExecutor.execute(() -> {
            logger.info("ThreadPoolExecutor");
        });
        // Map<String, String> contextMap = MDC.getCopyOfContextMap();
        MyThreadPoolExecutor myThreadPoolExecutor = new MyThreadPoolExecutor(2, 4, 1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(4));
        myThreadPoolExecutor.execute(() -> {
            logger.info("MyThreadPoolExecutor");
        });
        return "OK";
    }

}
